package com.ysq.excavator.common;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.ysq.excavator.entity.LoginUser;
import com.ysq.excavator.util.CommonUtil;
import com.ysq.excavator.util.LoggerUtil;

public class LoginInterceptor extends AbstractInterceptor {
	private static final long serialVersionUID = 1L;

	private static final String LUCENE_LOGIN = "luceneLogin";
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {

		// 取得请求相关的ActionContext实例
		ActionContext ctx = invocation.getInvocationContext();
		LoginUser user = (LoginUser) CommonUtil.getSessionAttribute("sessionLoginUser");

		//如果没有登陆
		if (user != null && "admin".equals(user.getUserName())) {
			return invocation.invoke();
		}else{
			LoggerUtil.logError("没有权限...");
			ctx.put("tip", "你还没有登录");
			return LUCENE_LOGIN;
		}
	}

}
